package cn.xiongxf.web.controller;

import cn.xiongxf.service.IMessageSmsService;
import cn.xiongxf.domain.MessageSms;
import cn.xiongxf.query.MessageSmsQuery;
import cn.xiongxf.result.JsonResult;
import cn.xiongxf.result.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/messageSms")
public class MessageSmsController {

    @Autowired
    public IMessageSmsService messageSmsService;

    /**
    * 带条件分页查询数据
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JsonResult page(@RequestBody MessageSmsQuery query){
        Page<MessageSms> page = new Page<MessageSms>(query.getPage(),query.getRows());
        page = messageSmsService.selectPage(page);
        return JsonResult.success(new PageList<MessageSms>(page.getTotal(),page.getRecords()));
    }

    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(messageSmsService.selectList(null));
    }

    /**
   * 查询单个对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResult get(@PathVariable("id")Long id){
        return JsonResult.success(messageSmsService.selectById(id));
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("id") Long id){
            messageSmsService.deleteById(id);
        return JsonResult.success();
    }

    /**
    * 保存/修改对象
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JsonResult saveOrUpdate(@RequestBody MessageSms messageSms){
        if(messageSms.getId()!=null){
            messageSmsService.updateById(messageSms);
        }else{
            messageSmsService.insert(messageSms);
        }
        return JsonResult.success();
    }

}
